<template>
	<view>
		<swiper class="screen-swiper square-dot" :indicator-dots="true" :circular="true" :autoplay="true"
			interval="5000" duration="500">
			<swiper-item v-for="(item,index) in goods.pic" :key="index">
				<image :src="item" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="bg-white flex padding">
			<view class="solid-right flex-sub">
				<view class="padding-right">
					<view class="margin-bottom">{{goods.title}}</view>
					<view class="text-price text-red text-xxl">{{goods.price}}</view>
				</view>
			</view>
			<view class="text-center flex align-center padding-left">
				<view @click="onShare()" class="lg cuIcon-share"></view>
			</view>
		</view>
		<view class="bg-white nav margin-tb">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="TabCur=='details'?'text-green cur':''"
					@click="tabSelect('details')">
					详情
				</view>
				<view class="cu-item flex-sub" :class="TabCur=='comment'?'text-green cur':''"
					@click="tabSelect('comment')">
					评论
				</view>
				<view class="cu-item flex-sub" :class="TabCur=='source'?'text-green cur':''"
					@click="tabSelect('source')">
					历史
				</view>
			</view>
		</view>

		<GoodsDetails :goods="goods" v-if="TabCur=='details'"></GoodsDetails>
		<GoodsComment :goods_id="goods.id" v-if="TabCur=='comment'"></GoodsComment>
		<GoodsSource :goods_id="goods.id" v-if="TabCur=='source'"></GoodsSource>

		<view class="foot-h"></view>
		<view class="cu-bar bg-white tabbar border shop foot">
			<button class="action" open-type="contact">
				<view class="cuIcon-service text-green">
					<view class="cu-tag badge"></view>
				</view>
				客服
			</button>
			<view class="action" @click="likeGoods()" :class="goods.is_like ? 'text-red':'text-gray'">
				<view class="lg cuIcon-appreciatefill"></view>
				<view>{{goods.is_like ? "已点赞":"点赞"}}</view>
			</view>
			<view @click="toAdvance()" class="bg-red submit">立即购买</view>
		</view>
	</view>
</template>

<script>
	import GoodsDetails from './details.vue'
	import GoodsComment from './comment/index.vue'
	import GoodsSource from './source.vue'
	import GoodsApi from "@/api/goods";
	import GoodsLikeApi from "@/api/goods_like";
	export default {
		components: {
			GoodsDetails,
			GoodsComment,
			GoodsSource
		},
		data() {
			return {
				swiperList: [],
				TabCur: 'details',
				goods: {}
			}
		},
		onLoad: function(option) {
			this.loadData(option.id)
		},
		methods: {
			loadData(id) {
				GoodsApi.get(id).then((res) => {
					this.goods = res;
				})
			},
			tabSelect(val) {
				this.TabCur = val;
			},
			toAdvance() {
				if (uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/order/advance?goods_id=' + this.goods.id
					});
				} else {
					uni.showToast({
						title: "未登录",
						icon: 'none'
					});
				}
			},
			likeGoods() {
				this.goods.is_like = true
				GoodsLikeApi.add({
					goods_id: this.goods.id
				}).then((res) => {

				})
			},
			onShare(){
				uni.share({
				    provider: "weixin",
				    scene: "WXSceneSession",
				    type: 2,
				    imageUrl: this.goods.qrcode,
				    success: function (res) {
				        console.log("success:" + JSON.stringify(res));
				    },
				    fail: function (err) {
				        console.log("fail:" + JSON.stringify(err));
				    }
				});
			}
		}
	}
</script>

<style>

</style>
